﻿// -----------------------------------------------------------------------
// <copyright file="Revisions_DAL.cs" company="">
// TODO: Update copyright text.
// </copyright>
// -----------------------------------------------------------------------

namespace PMSGSC.DAL
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;

    /// <summary>
    /// TODO: Update summary.
    /// </summary>
    public class Revisions_DAL:BaseDAL
    {
        
        // Lấy tất cả Revision
        public static List<Revision> GetAll(int JobDescrID)
        {
            DB.Refresh(System.Data.Linq.RefreshMode.OverwriteCurrentValues, DB.Revisions);
            return DB.Revisions.Where(n=>n.JobDescription_ID == JobDescrID).ToList();
        }
        // Lấy Revision theo Id
        public static Revision GetDataById(int id)
        {
            return DB.Revisions.Where(m => m.Revision_ID == id).FirstOrDefault();
        }
        public static Revision GetNewRevision()
        {
            return DB.Revisions.ToArray().LastOrDefault();
        }
        //Thêm một Revision
        public static bool Insert(Revision Revision)
        {
            try
            {
                DB.Revisions.InsertOnSubmit(Revision);
                DB.SubmitChanges();
                return true;
            }
            catch
            {
                return false;
            }

        }
        // Xóa một Revision
        public static bool Delete(Revision Revision)
        {
            try
            {
                DB.Revisions.DeleteOnSubmit(Revision);
                DB.SubmitChanges();
                return true;
            }
            catch
            {
                return false;
            }

        }
        // Cập nhật Revision
        public static bool Update(Revision Revision)
        {
            try
            {
                //Revision objRevision = GetDataById(Revision.Revision_ID);
                //objRevision.CodeJD = Revision.CodeJD;
                //objRevision.NameJD = Revision.NameJD;
                //objRevision.DetailsJD = Revision.DetailsJD;
                DB.SubmitChanges();
                return true;
            }
            catch
            {
                return false;
            }

        }
        public static int GetCountRevision(int id)
        {
            return DB.Revisions.Where(n => n.JobDescription_ID == id).Count();
        }

    }
}
